package org.darcy.service.check.impl;

import org.darcy.dao.CheckSpotMapper;
import org.darcy.entity.CheckSpot;
import org.darcy.framework.generic.GenericServiceImpl;
import org.darcy.framework.model.PageData;
import org.darcy.framework.model.PageParam;
import org.darcy.service.check.CheckSpotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import cn.hutool.core.util.StrUtil;

/**
 * CheckSpot服务实现
 */
@Service
@Transactional
public class CheckSpotServiceImpl extends GenericServiceImpl<CheckSpot> implements CheckSpotService {

	@Autowired
	private CheckSpotMapper mapper;

	@Override
	public CheckSpot getDetail(Integer id) {
		CheckSpot record = mapper.selectById(id);
		return record;
	}

	@Override
	public PageData<CheckSpot> page(PageParam<CheckSpot> param) {
		CheckSpot p = param.getEntity();
		QueryWrapper<CheckSpot> wrapper = new QueryWrapper<CheckSpot>();
		if (StrUtil.isNotEmpty(p.getItem())) {
			wrapper.eq("item", p.getItem());
		}
		if (StrUtil.isNotEmpty(p.getSpot())) {
			wrapper.like("spot", p.getSpot());
		}
		IPage page = new Page(param.getQuery().getPageNum(), param.getQuery().getPageSize());
		IPage list = this.getPage(page, wrapper);
		PageData data = new PageData(list, param);
		return data;
	}

}
